package academic.concordia.bankofquebec.bean.investmentaccount;

import java.util.Iterator;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import academic.concordia.bankofquebec.bean.bankAccount.IBankAccountServices;
import academic.concordia.bankofquebec.dao.bankaccount.IBankAccountDAO;
import academic.concordia.bankofquebec.dao.investmentaccount.IInvestmentAccountDAO;
import academic.concordia.bankofquebec.entity.InvestmentAccount;
import academic.concordia.bankofquebec.entity.Transaction;

@Transactional(readOnly = true)
public class InvestmentAccountServices implements IInvestmentAccountServices {

	IInvestmentAccountDAO investmentAccountDAO;
	
	IBankAccountServices bankAccountBean;
	
	IBankAccountDAO bankAccountDAO;
	
	@Override
	public void payInterests(InvestmentAccount account) {
		double interests = account.calculateInterests();
		account.depositInterests(interests);
		bankAccountDAO.updateBankAccount(account);
	}

	@Transactional(readOnly = false)
	@Override
	public void payAllInterests() {
		List<InvestmentAccount> accounts = investmentAccountDAO.getAccountToPayInterest();
		for (int i=0; i<accounts.size(); i++){
			InvestmentAccount account = accounts.get(i);
			payInterests(account);
		}

	}

	public IInvestmentAccountDAO getInvestmentAccountDAO() {
		return investmentAccountDAO;
	}

	public void setInvestmentAccountDAO(IInvestmentAccountDAO investmentAccountDAO) {
		this.investmentAccountDAO = investmentAccountDAO;
	}

	public IBankAccountServices getBankAccountBean() {
		return bankAccountBean;
	}

	public void setBankAccountBean(IBankAccountServices bankAccountBean) {
		this.bankAccountBean = bankAccountBean;
	}

	public IBankAccountDAO getBankAccountDAO() {
		return bankAccountDAO;
	}

	public void setBankAccountDAO(IBankAccountDAO bankAccountDAO) {
		this.bankAccountDAO = bankAccountDAO;
	}


}
